<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Project extends CI_Controller {

	public function __construct()
	{
		parent::__construct();
		$this->load->model('news_model');
		$this->load->model('project_model');
		$this->load->model('pacient_model');
		$this->load->model('register_pacient_model');
		$this->load->model('register_personal_model');
	}
	
	public function pacient()
	{
	   $data['jedalnicek'] = $this->pacient_model->povolene_jedla();
	   		$data['title'] = 'NIS - Pacient';
		$this->load->view('templates/header', $data);
	   $this->load->view('project/pacient', $data);  
	   	$this->load->view('templates/footer'); 	
	}
	
	public function sestra()
	{
		$data['dept'] = $this->project_model->get_dept($slug);
				$data['title'] = 'NIS - Sestra';
		$this->load->view('templates/header', $data);
		$this->load->view('project/sestra', $data); 
		$this->load->view('templates/footer');
		
	}
	
	
	function register_pacienta()
	{
		
	   $rodne_cisla_personalu = $this->register_personal_model->zoznam_rodnych_cisel_personalu();
       $rodne_cisla_pacientov = $this->register_pacient_model->zoznam_rodnych_cisel_pacientov();
	   $uziv_mena_personalu = $this->register_personal_model->zoznam_uziv_mien_personalu();
	   $uziv_mena_pacientov = $this->register_pacient_model->zoznam_uziv_mien_pacientov();
	   $uziv_mena_adminov = $this->register_personal_model->zoznam_uziv_mien_adminov();
	 
	 
 	    $pohlavie = array(
		'' => '',
		'Muz' => 'Muž',
		'Zena' => 'Žena',
		);

 	    $krvna_skupina = array(
		'' => '',
		'A' => 'A',
		'B' => 'B',
		'AB'=>'AB',
		'0'=>'0',
		);
		

		$diety[''] = '';

		
		$query = $this->register_pacient_model->zoznam_diet();
		foreach ($query as $row)
		{
			$diety[$row['ID']]=str_replace('-', ' ', $row['Meno']);
		}
		
		
            $this->load->library('form_validation');
            $this->load->helper('form');

            $this->options[] = 'Muž';


		$this->form_validation->set_rules('Meno', 'Meno', 'trim|required|xss_clean')
							  ->set_rules('Priezvisko', 'Priezvisko', 'trim|required|xss_clean')
							  ->set_rules('Rodne_cislo', 'Rodné číslo', 'trim|required|xss_clean|numeric')
							  ->set_rules('Uzivatelske_meno', 'Užívateľské meno', 'trim|required|xss_clean')
							  ->set_rules('Heslo', 'Heslo', 'trim|required|xss_clean|min_length[4]')
							  ->set_rules('Krvna_skupina', 'Krvná skupina', 'trim|xss_clean')
							  ->set_rules('Pohlavie', 'Pohlavie', 'trim|xss_clean')
							  ->set_rules('Dieta', 'Diéta', 'trim|required|xss_clean')
							  ->set_rules('Diagnoza', 'Diagnóza', 'trim|xss_clean');
			
			
			// ak prejde validaciou
	if ($this->form_validation->run())
		{		
		    $dane_rc = ($_POST['Rodne_cislo']);
			$dane_um = ($_POST['Uzivatelske_meno']);
		    $kontrola1 = 0;
		    foreach ($rodne_cisla_pacientov as $rc)
		    {
		  	       if ($rc['Rodne_cislo'] == $dane_rc)
			       {
			           $kontrola1++;
			       }
		    }
			$kontrola2 = 0;
		    foreach ($rodne_cisla_personalu as $rc)
		    {
		  	       if ($rc['Rodne_cislo'] == $dane_rc)
			       {
			           $kontrola2++;
			       }
		    }
			
			$kontrola3 = 0;
		    foreach ($uziv_mena_personalu as $rc)
		    {
		  	       if ($rc['Uzivatelske_meno'] == $dane_um)
			       {
			           $kontrola3++;
			       }
		    }
			
			$kontrola4 = 0;
		    foreach ($uziv_mena_pacientov as $rc)
		    {
		  	       if ($rc['Uzivatelske_meno'] == $dane_um)
			       {
			           $kontrola4++;
			       }
		    }
			
			$kontrola5 = 0;
		    foreach ($uziv_mena_adminov as $rc)
		    {
		  	       if ($rc['Uzivatelske_meno'] == $dane_um)
			       {
			           $kontrola5++;
			       }
		    }
			
		    if ($kontrola1 > 0 or $kontrola2 > 0)
		    {
		           print_r(' Rodné číslo je už v systéme');
		    }
			

			
			elseif
			(($kontrola3 > 0) or ($kontrola4 > 0) or ($kontrola5 > 0))
		    {
		           print_r(' Uživatelské meno je už v systéme');
		    }
			
			
		    else
	        { 
		          if ($this->register_pacient_model->register())
		          {
		  
		            	redirect('pacienti');
	              }
		
		          else
		          {
			      // chyba
			      print_r(' Chybne zadané Údaje ');
		          }
			}
		
		}
		
		
		
		
		
		
		
		$data['krvna_skupina'] = $krvna_skupina;
		$data['diety'] = $diety;
		$data['pohlavie'] = $pohlavie;	
		$data['title'] = 'NIS - Registrácia pacienta';
		$this->load->view('templates/header', $data);					  
		$this->load->view('project/registracia_pacienta', $data);
		$this->load->view('templates/footer');
	}
	
	
	
	function register_personalu()
	{
     $rodne_cisla_personalu = $this->register_personal_model->zoznam_rodnych_cisel_personalu();

     $rodne_cisla_pacientov = $this->register_pacient_model->zoznam_rodnych_cisel_pacientov();

	 $uziv_mena_personalu = $this->register_personal_model->zoznam_uziv_mien_personalu();
	 $uziv_mena_pacientov = $this->register_pacient_model->zoznam_uziv_mien_pacientov();
	 $uziv_mena_adminov = $this->register_personal_model->zoznam_uziv_mien_adminov();
		
	
		$cisla['$rodne_cisla_personalu']	= $rodne_cisla_personalu;
			
			

		$oddelenie[''] = '';

		$query = $this->register_personal_model->zoznam_oddeleni();
		foreach ($query as $row)
		{
			$oddelenie[$row['Nazov_oddelenia']]=$row['Nazov_oddelenia'];
		}
		
		
            $this->load->library('form_validation');
            $this->load->helper('form');

		$this->form_validation->set_rules('Meno', 'Meno', 'trim|required|xss_clean')
							  ->set_rules('Priezvisko', 'Priezvisko', 'trim|required|xss_clean')
							  ->set_rules('Rodne_cislo', 'Rodné číslo', 'trim|required|xss_clean|numeric')
							  ->set_rules('Uzivatelske_meno', 'Užívateľské meno', 'trim|required|xss_clean')
							  ->set_rules('Heslo', 'Heslo', 'trim|required|xss_clean|min_length[4]')
							  ->set_rules('Oddelenie', 'Oddelenie', 'trim|required|xss_clean')
							  ->set_rules('Specializacia', 'Špecializácia', 'trim|required|xss_clean');
			

	
			// ak prejde validaciou a uspesne sa zaregistruje
		if ($this->form_validation->run())
		{		
		    $dane_rc = ($_POST['Rodne_cislo']);
			$dane_um = ($_POST['Uzivatelske_meno']);
		    $kontrola1 = 0;
		    foreach ($rodne_cisla_pacientov as $rc)
		    {
		  	       if ($rc['Rodne_cislo'] == $dane_rc)
			       {
			           $kontrola1++;
			       }
		    }
			$kontrola2 = 0;
		    foreach ($rodne_cisla_personalu as $rc)
		    {
		  	       if ($rc['Rodne_cislo'] == $dane_rc)
			       {
			           $kontrola2++;
			       }
		    }
			
			$kontrola3 = 0;
		    foreach ($uziv_mena_personalu as $rc)
		    {
		  	       if ($rc['Uzivatelske_meno'] == $dane_um)
			       {
			           $kontrola3++;
			       }
		    }
			
			$kontrola4 = 0;
		    foreach ($uziv_mena_pacientov as $rc)
		    {
		  	       if ($rc['Uzivatelske_meno'] == $dane_um)
			       {
			           $kontrola4++;
			       }
		    }
			
			$kontrola5 = 0;
		    foreach ($uziv_mena_adminov as $rc)
		    {
		  	       if ($rc['Uzivatelske_meno'] == $dane_um)
			       {
			           $kontrola5++;
			       }
		    }
			
		    if ($kontrola1 > 0 or $kontrola2 > 0)
		    {
		           print_r(' Rodné číslo je už v systéme');
		    }
			

			
			elseif
			(($kontrola3 > 0) or ($kontrola4 > 0) or ($kontrola5 > 0))
		    {
		           print_r(' Uživatelské meno je už v systéme');
		    }
			
			
		    else
	        { 
		          if ($this->register_personal_model->register())
		          {
		  
		            	redirect('admin');
	              }
		
		          else
		          {
			      // chyba
			      print_r(' Chybne zadané Údaje ');
		          }
			}
		
		}
		$data['oddelenie'] = $oddelenie;	
		$data['title'] = 'NIS - Registrácia personálu';
		$this->load->view('templates/header', $data);	  
		$this->load->view('project/registracia_personalu', $data);
		$this->load->view('templates/footer');
		}
	
    
}